<%@ page import="com.situ.web.pojo.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="com.situ.web.util.PageInfo" %><%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/4/4
  Time: 20:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Title</title>
    <%@ include file="header.jsp"%>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/bootstrap-3.4.1-dist/css/bootstrap.css"/>
</head>
<body>
    <a class="btn btn-primary" href="<%=request.getContextPath()%>/student_add.jsp">添加</a>
    <table class="table table-striped table-bordered">
        <tr>
            <td>ID</td>
            <td>名字</td>
            <td>年龄</td>
            <td>性别</td>
            <td>删除</td>
        </tr>
        <c:forEach items="${pageInfo.list}" var="student">
            <tr>
                <td>${student.id}</td>
                <td>${student.name}</td>
                <td>${student.age}</td>
                <td>${student.gender}</td>
                <%--<td><a href="<%=request.getContextPath()%>/student?method=deleteById&id=<%=student.getId()%>">删除</a></td>--%>
                <td><a href="javascript:deleteById(${student.id})">删除</a></td>
            </tr>
        </c:forEach>
    </table>

    <nav aria-label="Page navigation">
        <ul class="pagination">
            <li>
                <a href="#" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
            <c:forEach begin="1" end="${pageInfo.totalPage}" var="i">
                <li><a href="${pageContext.request.contextPath}/student?method=selectByPage&pageNo=${i}">${i}</a></li>
            </c:forEach>
            <li>
                <a href="#" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        </ul>
    </nav>

    <script>
        function deleteById(id) {
            var isDelete = confirm('您确认要删除么?');
            if (isDelete) {
                //location.href = '<%=request.getContextPath()%>/student?method=deleteById&id=' + id
                $.post(

                );
                $.post(
                    '${pageContext.request.contextPath}/student?method=deleteById',
                    {'id': id},
                    function(jsonResult) {
                        console.log(jsonResult);
                        if (jsonResult.code == 0) {
                            mylayer.okUrl(jsonResult.msg, '${pageContext.request.contextPath}/student?method=selectByPage')
                        }
                    },
                    'json'
                );
            }
        }
    </script>
</body>
</html>
